import { GSprite } from "../../../../../com/mui/controls/GSprite";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { CrossGuildWarStage } from "../data/CrossGuildWarStage";
import { CrossGuildWarChooseForTop8N4N2N1Render } from "../render/CrossGuildWarChooseForTop8N4N2N1Render";
import { CrossGuildWarChooseForTop16Render } from "../render/CrossGuildWarChooseForTop16Render";
import { CrossGuildWarScheduleLiveRender } from "../render/CrossGuildWarScheduleLiveRender";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { CrossGuildWarChooseForTopLiveBg } from "../render/CrossGuildWarChooseForTopLiveBg";
import { CrossGuildWarChooseForTopData } from "../data/CrossGuildWarChooseForTopData";
import { CrossGuildWarStatusData } from "../data/CrossGuildWarStatusData";
import { Cache } from "../../../cache/Cache";
import { CrossGuildWarChooseForTopBtnRender } from "../render/CrossGuildWarChooseForTopBtnRender";
import { CrossGuildWarChooseForTopBtnData } from "../data/CrossGuildWarChooseForTopBtnData";
import { ResFileConst } from "../../../resource/ResFileConst";
import { CrossGuildWarChooseEnemyVSRender } from "../render/CrossGuildWarChooseEnemyVSRender";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ToolTipsManager } from "../../../../../com/mui/manager/ToolTipsManager";
import { CrossGuildWarGuideWin } from "../CrossGuildWarGuideWin";
import { ImgBtn } from "../../copy/btn/ImgBtn";
import { SecTimerView } from "../../common/SecTimerView";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class CrossGuildWarChooseForTopSubWin
    
    export  class CrossGuildWarChooseForTopSubWin extends GSprite
    {
        constructor()
        {
            super();
            this._arrForTops = [];
            return;
        }

        public updateList(arg1: int, arg2: DataProvider): void
        {
            this.showLiveMode(false);
            this.showForTop16Mode(false);
            DisplayUtil.removeMe(this._bmpVS);
            this._bigBg.visible = true;
            this._list.height = 250;
            var loc1=arg1;
            switch (loc1) 
            {
                case CrossGuildWarStage.ChooseForTop1:
                {
                    this._list.y = 335;
                    this._list.horizontalGap = 400;
                    this._list.verticalGap = 10;
                    this._list.x = 28;
                    this._list.columnWidth = 172;
                    this._list.rowHeight = 52;
                    this._list.setStyle("cellRenderer", CrossGuildWarChooseForTop8N4N2N1Render);
                    this.addChild(this._bmpVS);
                    break;
                }
                case CrossGuildWarStage.ChooseForTop2:
                {
                    this._list.y = 274;
                    this._list.horizontalGap = 200;
                    this._list.verticalGap = 72;
                    this._list.x = 28;
                    this._list.columnWidth = 372;
                    this._list.rowHeight = 52;
                    this._list.setStyle("cellRenderer", CrossGuildWarChooseForTop8N4N2N1Render);
                    this.addChild(this._bmpVS);
                    break;
                }
                case CrossGuildWarStage.ChooseForTop4:
                {
                    this._list.x = 28;
                    this._list.y = 260;
                    this._list.horizontalGap = 200;
                    this._list.verticalGap = 10;
                    this._list.columnWidth = 372;
                    this._list.rowHeight = 52;
                    this._list.setStyle("cellRenderer", CrossGuildWarChooseForTop8N4N2N1Render);
                    this.addChild(this._bmpVS);
                    break;
                }
                case CrossGuildWarStage.ChooseForTop8:
                {
                    this._list.x = 28;
                    this._list.y = 260;
                    this._list.columnWidth = 172;
                    this._list.rowHeight = 52;
                    this._list.horizontalGap = 20;
                    this._list.verticalGap = 10;
                    this._list.setStyle("cellRenderer", CrossGuildWarChooseForTop8N4N2N1Render);
                    break;
                }
                case CrossGuildWarStage.ChooseForTop16:
                {
                    this._list.y = 270;
                    this._list.horizontalGap = 1;
                    this._list.verticalGap = 0;
                    this._list.x = 10;
                    this._list.columnWidth = 194;
                    this._list.rowHeight = 28;
                    this._list.setStyle("cellRenderer", CrossGuildWarChooseForTop16Render);
                    this.showForTop16Mode(true);
                    this._bigBg.visible = false;
                    break;
                }
                case CrossGuildWarStage.FightForTop1: case CrossGuildWarStage.FightForTop2: case CrossGuildWarStage.FightForTop4: case CrossGuildWarStage.FightForTop8: case CrossGuildWarStage.FightForTop16:
                {
                    this._list.x = 0;
                    this._list.y = 271;
                    this._list.verticalGap = 0;
                    this._list.horizontalGap = 0;
                    this._list.width = 800;
                    this._list.height = 240;
                    this._list.columnWidth = 775;
                    this._list.rowHeight = 42;
                    this._list.setStyle("cellRenderer", CrossGuildWarScheduleLiveRender);
                    this.showLiveMode(true);
                    break;
                }
            }
            this._list.dataProvider = arg2;
            this._list.drawNow();
            return;
        }

        public showLiveMode(arg1: Boolean=true): void
        {
            var loc1=null;
            if (arg1) 
            {
                if (this._spLiveContainer == null) 
                {
                    this._spLiveContainer = new Object /* flash.display.Sprite */();
                    loc1 = GlobalStyle.textFormat2;
                    ObjCreate.createGTextField(Language.getString(57023), 148, 250, 100, 20, this._spLiveContainer, loc1);
                    ObjCreate.createGTextField(Language.getString(57023), 546, 250, 100, 20, this._spLiveContainer, loc1);
                    ObjCreate.createBg(5, 271, 786, 2, this._spLiveContainer, ImagesConst.SplitLine);
                    this._btnReflash = ObjCreate.createGButton(Language.getString(42213), 735, 247, 50, 22, this._spLiveContainer);
                    this._btnReflash.addEventListener(flash.events.MouseEvent.CLICK, this.clickReflashHandler);
                }
                this.addChild(this._spLiveContainer);
            }
            else 
            {
                DisplayUtil.removeMe(this._spLiveContainer);
                this._spLiveContainer = null;
            }
            return;
        }

        /* internal  */clickReflashHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGuildWarRefleshLive));
            return;
        }

        public showForTop16Mode(arg1: Boolean=true): void
        {
            var loc1=0;
            var loc2=null;
            if (!arg1) 
            {
                DisplayUtil.removeMe(this._spForTop16Container);
                return;
            }
            if (this._spForTop16Container == null) 
            {
                this._spForTop16Container = new Object /* flash.display.Sprite */();
                loc1 = 0;
                while (loc1 < 4) 
                {
                    loc2 = new CrossGuildWarChooseForTopLiveBg();
                    loc2.x = loc1 * 196 + 10;
                    loc2.y = 242;
                    this._spForTop16Container.addChild(loc2);
                    if (loc1 == 3) 
                    {
                        loc2.showHide(false);
                    }
                    ++loc1;
                }
            }
            this.addChild(this._spForTop16Container);
            return;
        }

        public updateSelfGuild(arg1: CrossGuildWarChooseForTopData, arg2: int): void
        {
            this._selfGuild.updateData(arg1);
            this._selfGuild.updateStatus(arg2);
            return;
        }

        public updateEnemyGuild(arg1: CrossGuildWarChooseForTopData, arg2: int): void
        {
            this._vsGuild.updateData(arg1);
            this._vsGuild.updateStatus(arg2);
            return;
        }

        public updateStatusTips(arg1: CrossGuildWarStatusData): void
        {
            if (arg1 == null) 
            {
                return;
            }
            if (arg1.leftSeconds <= 0) 
            {
                if (this._leftTime.running) 
                {
                    this._leftTime.stop();
                }
                this._leftTime.text = arg1.desc;
                if (arg1.desc.indexOf(":") >= 0) 
                {
                    this._leftTime.setLeftTime(Cache.instance.crossGuildWar.getRoundEndLeftSeconds());
                }
            }
            else 
            {
                this._leftTime.setParse(arg1.desc);
                this._leftTime.setLeftTime(arg1.leftSeconds);
            }
            return;
        }

        public updateTopBtns(arg1: Array<any>): void
        {
            var loc2=null;
            var loc1=0;
            while (loc1 < this._arrForTops.length) 
            {
                loc2 = this._arrForTops[loc1] as CrossGuildWarChooseForTopBtnRender;
                if (loc2 != null) 
                {
                    loc2.updateData(arg1[loc1] as CrossGuildWarChooseForTopBtnData);
                }
                ++loc1;
            }
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            ObjCreate.createBg(0, 0, 804, 97, this);
            this._forTop16 = new CrossGuildWarChooseForTopBtnRender(ResFileConst.CrossGuildWarBtn_For16);
            this._forTop16.x = 16;
            this._forTop16.y = 10;
            this.addChild(this._forTop16);
            this._forTop8 = new CrossGuildWarChooseForTopBtnRender(ResFileConst.CrossGuildWarBtn_For8);
            this._forTop8.x = 177;
            this._forTop8.y = 10;
            this.addChild(this._forTop8);
            this._forTop4 = new CrossGuildWarChooseForTopBtnRender(ResFileConst.CrossGuildWarBtn_For4);
            this._forTop4.x = 334;
            this._forTop4.y = 10;
            this.addChild(this._forTop4);
            this._forTop2 = new CrossGuildWarChooseForTopBtnRender(ResFileConst.CrossGuildWarBtn_For2);
            this._forTop2.x = 494;
            this._forTop2.y = 10;
            this.addChild(this._forTop2);
            this._forTop1 = new CrossGuildWarChooseForTopBtnRender(ResFileConst.CrossGuildWarBtn_For1);
            this._forTop1.x = 650;
            this._forTop1.y = 10;
            this.addChild(this._forTop1);
            this._arrForTops.push(this._forTop16);
            this._arrForTops.push(this._forTop8);
            this._arrForTops.push(this._forTop4);
            this._arrForTops.push(this._forTop2);
            this._arrForTops.push(this._forTop1);
            ObjCreate.createFlowerBg(0, 102, 804, 135, this);
            this._selfGuild = new CrossGuildWarChooseEnemyVSRender();
            this._selfGuild.x = 120;
            this._selfGuild.y = 120;
            this.addChild(this._selfGuild);
            var loc1=ObjCreate.createBitmap(null, 357, 108, this);
            LoaderHelp.setBitmapdata(ImagesConst.PetCpnVS + ".swf", loc1);
            this._vsGuild = new CrossGuildWarChooseEnemyVSRender();
            this._vsGuild.x = 492;
            this._vsGuild.y = 120;
            this.addChild(this._vsGuild);
            this._btnHelp = ObjCreate.createImgBtn(ImagesConst.RuleExplain, 717, 167, 60, 23, this, "Button");
            ToolTipsManager.register(this._btnHelp, null, Language.getString(80581));
            this._btnHelp.addEventListener(flash.events.MouseEvent.CLICK, this.clickHelpHandler);
            ObjCreate.createBg(220, 202, 380, 30, this, "RemainningTimeBg");
            var loc2=GlobalStyle.textFormat1;
            loc2.align = flash.text.TextFormatAlign.CENTER;
            loc2.size = 21;
            loc2.bold = true;
            loc2.color = 16776960;
            this._leftTime = ObjCreate.createSecTimeView("mm: ss", 0, 204, 800, 25, this, loc2);
            ObjCreate.createFlowerBg(0, 242, 804, 265, this);
            this._bigBg = ObjCreate.createBitmap(null, 0, 242, this);
            LoaderHelp.setBitmapdata("CrossGuildWarBgGrop.swf", this._bigBg);
            this._bmpVS = ObjCreate.createBitmap(null, 241, 266, this);
            LoaderHelp.setBitmapdata(ImagesConst.CrossGuildWarBgVS + ".swf", this._bmpVS);
            this._list = ObjCreate.createTileList(25, 245, 810, 250, this);
            return;
        }

        /* internal  */clickHelpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (flash.utils.getTimer() - this.lastClickTime <= 1000) 
            {
                return;
            }
            this.lastClickTime = flash.utils.getTimer();
            if (this._helpWin == null) 
            {
                this._helpWin = new CrossGuildWarGuideWin();
            }
            if (this._helpWin.isHide) 
            {
                this._helpWin.show();
            }
            else 
            {
                this._helpWin.hide();
            }
            return;
        }

        /* internal */ /* var */_selfGuild: CrossGuildWarChooseEnemyVSRender;

        /* internal */ /* var */_vsGuild: CrossGuildWarChooseEnemyVSRender;

        /* internal */ /* var */_btnHelp: ImgBtn;

        /* internal */ /* var */_helpWin: CrossGuildWarGuideWin;

        /* internal */ /* var */_leftTime: SecTimerView;

        /* internal */ /* var */_bmpVS: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_list: GTileList;

        /* internal */ /* var */_spLiveContainer: Object /* flash.display.Sprite */;

        /* internal */ /* var */_spForTop16Container: Object /* flash.display.Sprite */;

        /* internal */ /* var */_btnReflash: GButton;

        /* internal */ /* var */_forTop16: CrossGuildWarChooseForTopBtnRender;

        /* internal */ /* var */_forTop8: CrossGuildWarChooseForTopBtnRender;

        /* internal */ /* var */_forTop4: CrossGuildWarChooseForTopBtnRender;

        /* internal */ /* var */_forTop2: CrossGuildWarChooseForTopBtnRender;

        /* internal */ /* var */_forTop1: CrossGuildWarChooseForTopBtnRender;

        /* internal */ /* var */_arrForTops: Array<any>;

        /* internal */ /* var */_bigBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */lastClickTime: int=-10000;
    }
